package com.lagou.example;

import java.lang.reflect.Method;

public class TestTool {

    public static void main(String[] args) {
        NoBug noBug = new NoBug();
        Class<? extends NoBug> aClass = noBug.getClass();
        Method[] methods = aClass.getDeclaredMethods();
        StringBuilder testLog = new StringBuilder();
        int errorNum = 0;
        for (Method method : methods) {
            if ( method.isAnnotationPresent(Jiancha.class)) {
                try {
                    method.setAccessible(true);
                    method.invoke(noBug,null);
                } catch (Exception e) {
                    errorNum++;
                    testLog.append(method.getName());
                    testLog.append("  ");
                    testLog.append("has error :");
                    testLog.append("\n cause by ");
                    testLog.append(e.getCause().getClass().getSimpleName());
                    testLog.append("\n ");
                    testLog.append(e.getCause().getMessage());
                    testLog.append("\n ");
                }
            }
        }
        testLog.append(aClass.getSimpleName());
        testLog.append(" has ");
        testLog.append(errorNum);
        testLog.append(" error ");
        System.out.println(testLog.toString());
    }
}
